package com.ruoyi.web.controller.production.plug;

import java.util.List;

import com.ruoyi.common.annotation.PropertyInject;
import com.ruoyi.common.enums.InjectType;
import com.ruoyi.production.domain.carton.CartonPurchase;
import com.ruoyi.production.service.plug.IPlugAmountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.production.domain.plug.PlugPurchase;
import com.ruoyi.production.service.plug.IPlugPurchaseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 穴盘购买信息Controller
 *
 * @author ruoyi
 * @date 2021-07-12
 */
@RestController
@RequestMapping("/production/plugPurchase")
@Api(value = "穴盘购买",tags = "穴盘购买相关API")
public class PlugPurchaseController extends BaseController
{
    @Autowired
    private IPlugPurchaseService plugPurchaseService;
    @Autowired
    private IPlugAmountService plugAmountService;

    /**
     * 查询穴盘购买信息列表
     */
    @PreAuthorize("@ss.hasPermi('production:plugPurchase:list')")
    @GetMapping("/list")
    @ApiOperation("获取穴盘购买表信息")
    @ApiImplicitParam(name = "plugPurchase",value = "穴盘购买实体类",paramType = "body", dataType = "PlugPurchase")
    public TableDataInfo list(PlugPurchase plugPurchase)
    {
        startPage();
        List<PlugPurchase> list = plugPurchaseService.selectPlugPurchaseList(plugPurchase);
        return getDataTable(list);
    }

    /**
     * 导出穴盘购买信息列表
     */
    @PreAuthorize("@ss.hasPermi('production:plugPurchase:export')")
    @Log(title = "穴盘购买信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出穴盘购买表信息")
    @ApiImplicitParam(name = "plugPurchase",value = "穴盘购买实体类",paramType = "body", dataType = "PlugPurchase")
    public AjaxResult export(PlugPurchase plugPurchase)
    {
        List<PlugPurchase> list = plugPurchaseService.selectPlugPurchaseList(plugPurchase);
        ExcelUtil<PlugPurchase> util = new ExcelUtil<PlugPurchase>(PlugPurchase.class);
        return util.exportExcel(list, "穴盘购买信息数据");
    }

    /**
     * 获取穴盘购买信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('production:plugPurchase:query')")
    @GetMapping(value = "/{plugPurchaseId}")
    @ApiOperation("获取穴盘购买表单个信息")
    @ApiImplicitParam(name = "plugPurchaseId",value = "穴盘购买实体类主键",paramType = "path", dataType = "Long")
    public AjaxResult getInfo(@PathVariable("plugPurchaseId") Long plugPurchaseId)
    {
        return AjaxResult.success(plugPurchaseService.selectPlugPurchaseById(plugPurchaseId));
    }

    /**
     * 新增穴盘购买信息并更新穴盘量表
     */
    @PreAuthorize("@ss.hasPermi('production:plugPurchase:add')")
    @Log(title = "穴盘购买信息", businessType = BusinessType.INSERT)
    @PostMapping
    @PropertyInject(type = InjectType.Insert)
    @ApiOperation("新增穴盘购买表信息")
    @ApiImplicitParam(name = "plugPurchase",value = "穴盘购买实体类",paramType = "body", dataType = "PlugPurchase")
    public AjaxResult add(@RequestBody PlugPurchase plugPurchase)
    {
        return toAjax(plugPurchaseService.insertPurchaseUpdateAmount(plugPurchase));
    }

    /**
     * 修改穴盘购买信息
     */
    @PreAuthorize("@ss.hasPermi('production:plugPurchase:edit')")
    @Log(title = "穴盘购买信息", businessType = BusinessType.UPDATE)
    @PutMapping
    @PropertyInject(type = InjectType.Update)
    @ApiOperation("修改穴盘购买表信息")
    @ApiImplicitParam(name = "plugPurchase",value = "穴盘购买实体类",paramType = "body", dataType = "PlugPurchase")
    public AjaxResult edit(@RequestBody PlugPurchase plugPurchase)
    {
        return toAjax(plugPurchaseService.updatePlugPurchase(plugPurchase));
    }

    /**
     * 删除穴盘购买信息
     */
    @PreAuthorize("@ss.hasPermi('production:plugPurchase:remove')")
    @Log(title = "穴盘购买信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{plugPurchaseIds}")
    @ApiOperation("删除穴盘购买表信息")
    @ApiImplicitParam(name = "plugPurchaseIds",value = "穴盘购买实体类主键数组",paramType = "path", dataType = "Long")
    public AjaxResult remove(@PathVariable Long[] plugPurchaseIds)
    {
        return toAjax(plugPurchaseService.deletePlugPurchaseByIds(plugPurchaseIds));
    }
}
